package com.baijia.dao.impl;

import com.baijia.dao.IInternalServiceTokenDao;
import com.baijia.dao.po.InternalServiceToken;

import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.stereotype.Repository;

import lombok.extern.slf4j.Slf4j;

@Repository
@Slf4j
public class InternalServiceTokenDaoImpl extends CommonDaoImpl<InternalServiceToken, Long> implements
    IInternalServiceTokenDao {

    public InternalServiceTokenDaoImpl() {
        super(InternalServiceToken.class);
    }

    private String SELECT_SQL = "select id, sid, token from yunying.passport_internal_service_token";

    @Override
    public String getToeknBySid(Integer sid) {
        try {
            InternalServiceToken serviceToken =
                jdbcTemplateService.queryForObject(SELECT_SQL + " where sid=?", new BeanPropertyRowMapper<>(
                    InternalServiceToken.class), new Object[] { sid });
            return serviceToken != null ? serviceToken.getToken() : null;
        } catch (Exception e) {
            log.error("getToeknBySid failed. sid=" + sid, e);
        }

        return null;
    }

    @Override
    protected String selectSql() {
        return SELECT_SQL;
    }

}
